<?php
/**
 * Created by PhpStorm.
 * User: HP
 * Date: 2018/9/11
 * Time: 10:22
 */
namespace App\Http\Controllers;

use App\Models\Book;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use App\Models\Category;

class CategoryController extends Controller {

//增加目录
    public function addCategory(Request $request){
        $name = $request->input('name');
        $result  = Category::addCategory($name);
        if(isset($result)){
            return $this->success($result->cid);
        }else{
            return $this->fail(500003,'目录已存在');
        }
    }

//目录列表
    public function categoryList(){
        $result = Category::getList();
        if($result != null){
            return $this->success($result);
        }else{
            return $this->fail(500002,'目录不存在或服务器未响应');
        }
    }

    public function categoryDetail(Request $request){
        $cid = $request->input('cid');
        $result = Book::categoryDetail($cid);
        if(isset($result)){
            return $this->success($result);
        }else{
            return $this->fail(500002,'该目录下暂无图书');
        }
    }
}